package hlkj.server;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.jfinal.kit.PropKit;

import jxl.common.Logger;
import hlkj.util.ConnectionUrlUtil;
import hlkj.util.ServiceMsg;
import hlkj.util.ServiceMsg.SimplMsg;
import lxycx.util.http.RequestPro;
import net.sf.json.JSONObject;

public class Ahdx_SMS extends SendOut{
	private static Logger log = Logger.getLogger(Ahdx_SMS.class);
	
	//发送短信
	public  String send_msg(String phone,String msg){
		try {
			String xml  = "<sms> <systemid>weChat</systemid>"
					+ "<smstype>sendMsg</smstype> " + "<msisdn>" + phone
					+ "</msisdn>" + "<msgcontent>" + URLEncoder.encode(msg, "GB18030") + "</msgcontent>"
					+ "<reserve></reserve></sms>";
			String ret = ConnectionUrlUtil.sendPost("http://134.64.60.105:8008/send?smsmsg="
					+ xml, "");

			return "0".equals(ret)?ret:"发送失败";
		} catch (UnsupportedEncodingException e) {
			log.error("短信发送失败",e);
			return "发送异常";
		}
	}
	
	
	protected String getToken() {
		String url = PropKit.get("ahdx.tokenUrl","http://ahdx.10006.info/weiXinApiService/api/cgi-bin/token");
		String retjson = RequestPro.send(url, null);
		JSONObject json = JSONObject.fromObject(retjson);
		log.info("TokenJson:"+json);
		return json.containsKey("access_token")?json.getString("access_token"):"";
	}
	
}
